package com.moyun.zbmy.zizhou.ui.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.moyun.zbmy.zizhou.R;
import com.moyun.zbmy.zizhou.beans.SubscriptionNoBean;
import com.moyun.zbmy.zizhou.ui.adapter.SubscriptionNoAdapter;
import com.moyun.zbmy.zizhou.ui.utils.GlideCircleTransform;
import com.moyun.zbmy.zizhou.ui.utils.GlideUtil;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 订阅号item
 */
public class SubscriptionNoListHolder extends BaseAbsHolder<SubscriptionNoBean> implements View.OnClickListener {

    @BindView(R.id.subscription_no_img)
    protected ImageView img;
    @BindView(R.id.subscription_no_name)
    protected CustomFontTextView name;


    private int type = 0;//0 默认为纵向列表，1 为GridView
    private SubscriptionNoBean temp;
    private GlideCircleTransform circleTransform;
    private SubscriptionNoAdapter.OnSubscriptionNoClickListener subscriptionNoClickListener;

    public SubscriptionNoListHolder(Context context, View itemView, SubscriptionNoAdapter.OnSubscriptionNoClickListener subscriptionNoClickListener) {
        super(context, itemView);
        itemView.setOnClickListener(this);
        this.subscriptionNoClickListener = subscriptionNoClickListener;
    }

    public SubscriptionNoListHolder(Context context, View itemView, int type, SubscriptionNoAdapter.OnSubscriptionNoClickListener accountClickListener) {
        super(context, itemView);
        itemView.setOnClickListener(this);
        this.type = type;
        this.subscriptionNoClickListener = subscriptionNoClickListener;
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(SubscriptionNoBean t) {
        temp = t;
        circleTransform = new GlideCircleTransform(context);
        name.setText(t.getWxName());
        GlideUtil.getCircleGlid(context, t.getWxImage(), true).diskCacheStrategy(DiskCacheStrategy.NONE).transform(circleTransform).into(img);
    }

    @Override
    public void setItemMode(int mode) {
        super.setItemMode(mode);

    }

    @Override
    public void onDestory() {
        super.onDestory();
        if (itemView != null) {
            itemView.setOnClickListener(null);
        }
    }

    @Override
    public void onClick(View v) {
        if (temp == null) {
            Toast.makeText(context, "数据错误", Toast.LENGTH_SHORT).show();
            return;
        }
        if (null != subscriptionNoClickListener) {
            subscriptionNoClickListener.OnSubscriptionNoClick(temp);
        }
    }

}
